<include file="public/header" />
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">分类</a>
                <a>
                    <cite>分类列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<form class="layui-form">

    <div class="layui-form-item" >
        <label class="layui-form-label">全选</label>
        <div class="layui-input-block">
            <input type="checkbox"  lay-filter="all" title="全选/取消全选" value="all" class="layui-btn">
        </div>
    </div>
    <foreach name="list" item="vo">
    <div class="layui-form-item">
        <label class="layui-form-label">{$vo.name}</label>
        <if condition="$vo.child !== ''">
            <div class="layui-input-block">
                <foreach name="vo.child" item="vv">
                    <input type="checkbox" value="{$vv.id}" <if condition="$vv.show eq 1">checked</if>  name="right_list[]" title="{$vv.name}">
                </foreach>
            </div>
        </if>
    </div>
    </foreach>
    <div class="layui-form-item" >
        <div class="layui-input-block">
            <input type="hidden" name="role_id" value="{$id}">
            <button type="button"  class="layui-btn" lay-submit=""  lay-filter="addEdit">保存</button>
        </div>
    </div>
</form>


<script>
    layui.use(['table', 'util'], function () {

    var  form = layui.form;

        form.on('checkbox(all)', function (data) {
            $("input[name='right_list[]']").each(function () {
                this.checked = data.elem.checked;
// console.log(data);
            });
            form.render('checkbox');
        });

            form.on('submit(addEdit)', function(data){
            $.post($('form').attr('action'),data.field,function(data){
                if(data.code == 200){
                    layer.msg(data.msg);
                    setTimeout(function () {
                        window.history.back();
                    },2000)
                    xadmin.close();
                    xadmin.father_reload();
                }else {
                    layer.msg(data.msg);
                }
            });
            return false;
        });
    });
</script>